var page = require('webpage').create(), system = require('system');
if (system.args.length === 1) {
	phantom.exit();
} else {
	var address = system.args[1];
	page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0';
	page.settings.javascriptEnabled = true;
	page.onResourceRequested = function (req) {

	//console.log('requested: ' + JSON.stringify(req, undefined, 4));
	// console.log(JSON.parse(JSON.stringify(req, undefined, 4)).url);
	};
	page.open(address, function(status) {
		if (status !== 'success') {
	    	phantom.exit();
		}else {
			var sc = page.evaluate(function() {
			    return document.getElementsByTagName('html')[0].innerHTML;
			    //return document.documentElement.innerHTML;
			});
			window.setTimeout(function() {
				console.log(sc);
//			    console.log('----');
//			    console.log(page.content);
			    phantom.exit();
			}, 1000)
		}
	})
}